package com.ruoyi.experiment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.experiment.domain.TeachingExperimentalEnvironment;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.experiment.domain.TeachingExperimentalEnvironmentExample;
import com.ruoyi.experiment.service.ITeachingExperimentalEnvironmentExampleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教学实验环境实例Controller
 * 
 * @author ruoyi
 * @date 2023-07-29
 */
@RestController
@RequestMapping("/experiment/example")
public class TeachingExperimentalEnvironmentExampleController extends BaseController
{
    @Autowired
    private ITeachingExperimentalEnvironmentExampleService teachingExperimentalEnvironmentExampleService;

    /**
     * 查询教学实验环境实例列表
     */
    @PreAuthorize("@ss.hasPermi('experiment:example:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachingExperimentalEnvironmentExample teachingExperimentalEnvironmentExample)
    {
        startPage();
        List<TeachingExperimentalEnvironmentExample> list = teachingExperimentalEnvironmentExampleService.selectTeachingExperimentalEnvironmentExampleList(teachingExperimentalEnvironmentExample);
        return getDataTable(list);
    }

    /**
     * 导出教学实验环境实例列表
     */
    @PreAuthorize("@ss.hasPermi('experiment:example:export')")
    @Log(title = "教学实验环境实例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeachingExperimentalEnvironmentExample teachingExperimentalEnvironmentExample)
    {
        List<TeachingExperimentalEnvironmentExample> list = teachingExperimentalEnvironmentExampleService.selectTeachingExperimentalEnvironmentExampleList(teachingExperimentalEnvironmentExample);
        ExcelUtil<TeachingExperimentalEnvironmentExample> util = new ExcelUtil<TeachingExperimentalEnvironmentExample>(TeachingExperimentalEnvironmentExample.class);
        util.exportExcel(response, list, "教学实验环境实例数据");
    }

    /**
     * 获取教学实验环境实例详细信息
     */
    @PreAuthorize("@ss.hasPermi('experiment:example:query')")
    @GetMapping(value = "/{teachingEnvironmentExampleId}")
    public AjaxResult getInfo(@PathVariable("teachingEnvironmentExampleId") Long teachingEnvironmentExampleId)
    {
        return success(teachingExperimentalEnvironmentExampleService.selectTeachingExperimentalEnvironmentExampleByTeachingEnvironmentExampleId(teachingEnvironmentExampleId));
    }

    /**
     * 新增教学实验环境实例
     */
    @PreAuthorize("@ss.hasPermi('experiment:example:add')")
    @Log(title = "教学实验环境实例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachingExperimentalEnvironmentExample teachingExperimentalEnvironmentExample)
    {
        return toAjax(teachingExperimentalEnvironmentExampleService.insertTeachingExperimentalEnvironmentExample(teachingExperimentalEnvironmentExample));
    }

    /**
     * 修改教学实验环境实例
     */
    @PreAuthorize("@ss.hasPermi('experiment:example:edit')")
    @Log(title = "教学实验环境实例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachingExperimentalEnvironmentExample teachingExperimentalEnvironmentExample)
    {
        return toAjax(teachingExperimentalEnvironmentExampleService.updateTeachingExperimentalEnvironmentExample(teachingExperimentalEnvironmentExample));
    }

    /**
     * 删除教学实验环境实例
     */
    @PreAuthorize("@ss.hasPermi('experiment:example:remove')")
    @Log(title = "教学实验环境实例", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teachingEnvironmentExampleIds}")
    public AjaxResult remove(@PathVariable Long[] teachingEnvironmentExampleIds)
    {
        return toAjax(teachingExperimentalEnvironmentExampleService.deleteTeachingExperimentalEnvironmentExampleByTeachingEnvironmentExampleIds(teachingEnvironmentExampleIds));
    }

    /**
     * 重做实验
     */
    @GetMapping("/resetExperiment/{teeId}")
    public AjaxResult resetExperiment(@PathVariable Long teeId)
    {
        teachingExperimentalEnvironmentExampleService.resetExperiment(teeId);
        return new AjaxResult(200,"重做实验成功");
    }

    /**
     * 结束实验
     */
    @GetMapping("/endExperiment/{teeId}")
    public AjaxResult endExperiment(@PathVariable Long teeId)
    {
        teachingExperimentalEnvironmentExampleService.endExperiment(teeId);
        return new AjaxResult(200,"结束实验成功");
    }

    /**
     * 增加实验时间
     */
    @GetMapping("/addExperimentTime/{teeId}")
    public AjaxResult addExperimentTime(@PathVariable Long teeId)
    {
        teachingExperimentalEnvironmentExampleService.addExperimentTime(teeId);
        return new AjaxResult(200,"增加实验成功");
    }
}
